﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using uMES.LeanManufacturing.ReportBusiness;
using System.Drawing;
using Infragistics.WebUI.Misc;

/// <summary>
///PageBase 的摘要说明
/// </summary>
public class PageBase : System.Web.UI.Page
{
    public PageBase()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    private uMESLoginBusiness bll = new uMESLoginBusiness();

    WebAsyncRefreshPanel warp;
    public WebAsyncRefreshPanel WebPanel
    {
        set
        {
            warp = value;
        }
    }
    protected override void OnInit(EventArgs e)
    {
        if (Session["loginInfo"] == null)
        {
            HttpCookie cookie = Request.Cookies.Get("current_LoginUserName");
            if (cookie != null)
            {
                string LoginUserName = cookie.Values["LoginUserName"];
                DataTable dt = bll.GetLoginInfo(LoginUserName);
                Session["loginInfo"] = dt;
            }
        }
        base.OnInit(e);
    }

    /// <summary>
    /// 清除消息
    /// </summary>
    protected virtual void ClearMessage()
    {
        DisplayMessage("", true);
    }

    /// <summary>
    /// 提示信息
    /// </summary>
    /// <param name="strMessage"></param>
    /// <param name="boolResult"></param>
    protected virtual void DisplayMessage(string strMessage, Boolean boolResult)
    {
        //strMessage = strMessage.Trim(new[] { '\r', '\n' });
        //处理特殊字符 add:Wangjh
        strMessage = strMessage.Replace("\"", "");
        strMessage = strMessage.Replace("\r", "");
        strMessage = strMessage.Replace("\n", "");

        string strScript = "<script>ShowMessage(\"" + strMessage + "\", " + boolResult.ToString().ToLower() + ");</script>";
        if (warp != null)
            Infragistics.WebUI.Shared.CallBackManager.AddScriptBlock(Page, warp, strScript);
        else 
            ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), strScript);
    }

    /// <summary>
    /// 提示信息
    /// </summary>
    /// <param name="strMessage"></param>
    /// <param name="boolResult"></param>
    public void DisplayMessage(System.Web.UI.WebControls.Label label, string strMessage, Boolean boolResult)
    {
        label.Text = strMessage;
        label.Font.Size = 14;
        if (boolResult == true)
        {
            label.ForeColor = Color.Black;
        }
        else
        {
            label.ForeColor = Color.Red;
        }
    }

    /// <summary>
    /// 执行js脚本
    /// </summary>
    /// <param name="strScript"></param>
    public void ExcuteScript(string strScript) {
        if(warp!=null)
            Infragistics.WebUI.Shared.CallBackManager.AddScriptBlock(Page, warp, strScript);
        else
            ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), strScript);
    }
}